package article;

import course.shared.PMF;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;
import course.*;
import java.util.*;
import java.text.*;
/**
 * Servlet implementation class addArticleServlet
 */
public class addArticleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		Long course = Long.parseLong(request.getParameter("course"));
		String member = request.getParameter("member");
		
		java.util.Date d1 = new java.util.Date();
		SimpleDateFormat sdfmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		d1 = cal.getTime();
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			Course c = pm.getObjectById(Course.class,course);
			c.addArt(c, member, title, sdfmt.format(d1), content);
		} finally {
		    pm.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
